package com.sxbang.bms.dao;

import com.sxbang.bms.base.BaseDao;
import com.sxbang.bms.model.SysPermission;
import com.sxbang.bms.model.SysRole;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PermissionDao {

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into sys_permission(parentId, name, css, href, type, permission, sort) values(#{parentId}, #{name}, #{css}, #{href}, #{type}, #{permission}, #{sort})")
    public int save(SysPermission e);

//    public int save(List<SysPermission> es);

    @Select("select * from sys_permission t where t.id = #{id}")
    public SysPermission get(Integer id);

    @Select("select * from sys_permission t")
    public List<SysPermission> findAll();

    @Select("select p.* from sys_permission p inner join sys_role_permission rp on p.id = rp.permissionId where rp.roleId = #{roleId} order by p.sort")
    List<SysPermission> listByRoleId(Integer roleId);

//    public List<SysPermission> list (Iterable<Integer> ids);

    @Select("select * from sys_permission t limit #{offset},#{limit}")
    public List<SysPermission> listByPage(@Param("offset") Integer offset, @Param("limit") Integer limit);

    @Select("select * from sys_permission t where  t.name like '%${name}%'")
    public List<SysPermission> listByName(@Param("roleName") String name);

    @Select("select * from sys_permission t where  t.name like '%${name}%' limit #{offset},#{limit}")
    public List<SysPermission> listByNameAndPage(@Param("name") String name, @Param("offset") Integer offset, @Param("limit") Integer limit);

    public int update(SysPermission e);

    @Delete("delete from sys_permission where id = #{id}")
    public int delete(SysPermission e);

    @Delete("delete from sys_permission where id = #{id}")
    public int deleteById(Integer id);

    @Select("select count(*) from sys_permission t")
    public Long countAll();

    @Select("select count(*) from sys_permission t where t.name like '%${name}%'")
    public Long countByName(@Param("name") String name);
}
